package com.example.mapper;

import com.example.model.BookInfo;
import com.example.model.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-07-23
 * Time: 21:31
 */
@Mapper
public interface BookInfoMapper {


    /**
     * 增加图书
     * @param bookInfo
     * @return
     */
    @Insert("insert into book_info(book_name,author,count,price,publish,status) values(#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo bookInfo);

    //实现翻页查询
    @Select("select * from book_info where status != 0 limit #{offset},#{pageSize}")
    List<BookInfo> selectBookPage(PageRequest pageRequest);

    @Select("select count(*) from book_info where status != 0")
    Integer count();



    /*
    修改图书
    1.根据id查询图书信息
    2.根据前端输入的图书信息更新到数据库中
     */
    @Select("select * from book_info where id = #{id}")
    BookInfo queryBookById( Integer id);
    //修改图书
    Integer updateBook(BookInfo bookInfo);


    /**
     * 删除图书
     * @param id
     * @return
     */
    @Update("update book_info set status = 0 where id = #{id}")
    Integer deleteBook(Integer id);


    /*
    批量删除图书
     */
    Integer batchDeleteBook( List<Integer> bookIds);
}
